package shudu;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @author 田野
 * @version 创建时间：2014年1月2日 下午1:39:51
 * 
 */
public class Genius {

	public void guess(Chessboard chessboard) {
		Draft draft = new Draft(chessboard);

		// for (int i = 0; i < chessboard.getWidth(); i++) {
		// for (int j = 0; j < chessboard.getWidth() ; j++) {
		// draft.addCellAt(chessboard.getCell(i, j), i, j);
		// }
		// }
		int guessNoneTime = 0;
		while (true) {
			int doneCount = draft.doneCount;
			
			draft.checkAll();
			
			if (draft.doneCount == chessboard.getHeight()
					* chessboard.getWidth()) {
				System.out.println("done");
				break;
			} else if (draft.doneCount == doneCount) {
				guessNoneTime++;
			} else {
				guessNoneTime = 0;
			}
			if (guessNoneTime == 4) {
				System.out.println("i can't guess anymore");
				System.out.println(draft);
				break;
			}
		}
		for (int i = 0; i < chessboard.getWidth(); i++) {
			for (int j = 0; j < chessboard.getHeight(); j++) {
				if (chessboard.getCell(i, j).number == null) {
					chessboard.getCell(i, j).number = draft.getCell(i, j).number;
				}
			}
		}
		System.out.println(chessboard);
	}

}
